import sqlite3


def connect():
    con = sqlite3.connect('example.db')
    return con


def insert(key, value=None):
    if value:
        key = str(key)
        if ';' in key or '"' in key or "'" in key:
            return False

        con = connect()
        cur = con.cursor()
        cur.execute(f"SELECT value FROM example WHERE key = '{key}'")
        res = cur.fetchall()
        # print(f"SELECT value FROM example WHERE key = '{key}'")
        # print(res)

        if res:
            # print(f"UPDATE example SET value = '{value}' WHERE key = '{key}'")
            cur.execute(f"UPDATE example SET value = '{value}' WHERE key = '{key}'")
            con.commit()
        else:
            # print(f"INSERT INTO example VALUES ('{key}', '{value}')")
            cur.execute(f"INSERT INTO example VALUES ('{key}', '{value}')")
            con.commit()
        con.close()


def query(key):
    con = connect()
    cur = con.cursor()
    cur.execute(f"SELECT value FROM example WHERE key = '{key}'")
    res = cur.fetchall()
    # print(f"SELECT value FROM example WHERE key = '{key}'")
    # print(res)
    con.close()
    return res
